<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>应急指挥辅助决策系统</title>
<link href="../styles/edas_back.css" rel="stylesheet" type="text/css" />
</head>

<style type="text/css">
body {
	background-image: url(../images/bg.png);
}
</style>
<body>
	<div id="mainContainer"
		style="width: 1024px; Margin-Right: auto; Margin-Left: auto;"
		align="center">

		<div id="logoPic" style="margin-top: 80px">
			<img src="../images/tb.png" />
		</div>

		<div>
			<font id="error_msg" color="red"></font>
		</div>

		<div id="loginForm"
			style="width: 500px; height: 200px; background-color: white; margin-top: 20px">

			<input id="username" name="username" size="30" placeholder="账号" title="欧尼"
				value="" class="input_1" style="margin-top: 20px;" /> <br> <input
				name="password" id="password" type="password" placeholder="密码" class="input_1"
				style="margin-top: 10px" /> <br> <input type="button"
				value="登录" class="btn_3" id="login_btn" style="margin-top: 15px" />

		</div>
	</div>
	<script src="../js/jquery1.9.1.js" type="text/javascript"></script>
	<script>
		$(function() {
			
			var ie = !-[1,];  
			if(ie){
				forIE();
			}
			$('#username').focus();
			
			$('#username').blur(
				function(){
					$(this).removeClass("validation-failed");
				}		
			);
			
			$('#password').blur(
					function(){
						$(this).removeClass("validation-failed");
					}		
				);
			$('#login_btn').click(function() {
				if ($('#username').val() == '' || $('#username').val() == '账号') {
					$('#error_msg').html('请输入用户名');
					$('#username').addClass("validation-failed");
					$('#username').focus();
					return;
				} else if ($('#password').val() == '') {
					$('#error_msg').html('请输入密码');
					$('#password').addClass("validation-failed");
					$('#password').focus();
					return;
				}
				jQuery.ajax({
					type : 'Get',
					contentType : 'application/json',
					url : '../login/login.do',
					data : {
						username : $('#username').val(),
						password : $('#password').val()
					},
					dataType : 'json',
					success : function(obj) {
						if (!obj.result) {
							$('#error_msg').html('用户名或密码错误');
							$('#username').addClass("validation-failed");
							$('#password').addClass("validation-failed");
						} else {
							location.href = "./index.html";
						}

					},
					error : function(data) {
						alert("error")
					}
				});
			});

			//回车事件
			document.onkeydown = function(e) {
				var ev = document.all ? window.event : e;
				if (ev.keyCode == 13) {
					$('#login_btn').click();
				}
			}

		});

		function forIE() {
			var doc = document, inputs = doc.getElementsByTagName('input'), supportPlaceholder = 'placeholder' in doc
					.createElement('input'), placeholder = function(input) {
				var text = input.getAttribute('placeholder'), defaultValue = input.defaultValue;
				if (defaultValue == '') {
					input.value = text
				}
				input.onfocus = function() {
					if (input.value === text) {
						this.value = ''
					}
				};
				input.onblur = function() {
					if (input.value === '') {
						this.value = text
					}
				}
			};
			if (!supportPlaceholder) {
				for ( var i = 0, len = inputs.length; i < len; i++) {
					var input = inputs[i], text = input
							.getAttribute('placeholder');
					if (input.type === 'text' && text) {
						placeholder(input)
					}
				}
			}
		}
	</script>
</body>
</html>